package com.system.orders.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.system.common.bean.SeckillOrders;
import com.system.common.service.ISeckillOrdersService;
import com.system.common.util.Result;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/seckillorders")
public class SeckillOrdersController {

    @DubboReference
    private ISeckillOrdersService seckillOrdersService;

    @PostMapping("/add")
    public Result add(@RequestBody SeckillOrders seckillOrder){
        seckillOrdersService.addSeckillOrder(seckillOrder);
        return Result.ok("添加秒杀订单成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        seckillOrdersService.deleteSeckillOrder(id);
        return Result.ok("删除秒杀订单成功");
    }

    @PutMapping("/update")
    public Result update(@RequestBody SeckillOrders seckillOrder){
        seckillOrdersService.updateSeckillOrder(seckillOrder);
        return Result.ok("修改秒杀订单成功");
    }

    @GetMapping("/list")
    public Result list(){
        return Result.ok("获取秒杀订单列表成功", seckillOrdersService.getAll());
    }

    @GetMapping("/page")
    public Result page(SeckillOrders seckillOrder,
                       @RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        return Result.ok("获取秒杀订单分页列表成功", seckillOrdersService.getPage(seckillOrder, new Page<>(pageNum, pageSize)));
    }

    @GetMapping("/getById/{id}")
    public Result getById(@PathVariable Integer id){
        return Result.ok("获取秒杀订单成功", seckillOrdersService.getById(id));
    }

    @GetMapping("/getByUserId/{userid}")
    public Result getByUserId(@PathVariable Integer userid){
        return Result.ok("获取用户秒杀订单列表成功", seckillOrdersService.getByUserId(userid));
    }

    @GetMapping("/getByActivityId/{activityid}")
    public Result getByActivityId(@PathVariable Integer activityid){
        return Result.ok("获取活动秒杀订单列表成功", seckillOrdersService.getByActivityId(activityid));
    }

    @GetMapping("/getByUserGoodsActivity")
    public Result getByUserGoodsActivity(@RequestParam Integer userid,
                                         @RequestParam Integer activityid,
                                         @RequestParam Integer goodsid){
        return Result.ok("获取用户秒杀订单成功",
                seckillOrdersService.getByUserIdAndActivityIdAndGoodsId(userid, activityid, goodsid));
    }
}
